package com.deli.studypay;


import com.google.common.util.concurrent.RateLimiter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping(value = "/", produces = "application/json; charset=utf-8")
public class PayController {

    final RateLimiter rateLimiter = RateLimiter.create(2);

    @RequestMapping("/pay")
    public String sendPayment(@RequestParam(required = true) String orderid ) {
        if (rateLimiter.tryAcquire(2)) {
            Date date = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
            String begTime = format.format(date);
            System.out.println(begTime);
            return "支付成功";
        } else {
            return "支付失敗";
        }
    }
}
